<template>
    {{ formatt() }}
</template>

<script setup>
const props = defineProps({
    list: {
        type: Array,
        required: true,
    },
    mapping: {
        type: Array,
        default: ['code', 'name']
    },
    id: String
})
const formatt = () => {
    if (props.list && props.list.length && props.id) {
        return props.list.find(item => item[props.mapping[0]] == props.id) ? props.list.find(item => item[props.mapping[0]] == props.id)[props.mapping[1]] : ''
    } else {
        return ''
    }
}

watch(
    () => props.list,
    (newValue) => {
        formatt()
    },
    { deep: true, immediate: true }
);
</script>

<style></style>